<?php

namespace App\Admin\Models;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{
    public static $sales = [
        0 => '正常',
        1 => '推荐'
    ];
    
    public function __construct()
    {
        parent::__construct();
        
        $this->setTable('goods');
    }
    
    public static function getSales($key = null)
    {
        if (!$key) {
            return static::$sales;
        } else {
            if (!array_key_exists($key, static::$sales)) {
                throw new \Exception('未知sale状态');
            }
            return static::$sales[$key];
        }
    }
    
    public function type()
    {
        return $this->belongsTo(Type::class);
    }
    
    public function style()
    {
        return $this->belongsTo(Style::class);
    }
    
    public function material()
    {
        return $this->belongsTo(Material::class);
    }
    
    public function shape()
    {
        return $this->belongsTo(Shape::class);
    }
    
    public function group()
    {
        return $this->belongsTo(Group::class);
    }
}
